package com.epoint.bookmanagement.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;

@WebFilter("/*")
public class EncodingFilter  implements Filter{
	
	@Override
    public void init(FilterConfig filterConfig) throws ServletException {
        // 初始化过滤器时调用的方法，可以在这里进行一些资源的初始化操作
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException {
        // 设置请求和响应的编码为UTF-8
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");

        // 继续执行后续的过滤器和请求处理
        chain.doFilter(request, response);
    }

    @Override
    public void destroy() {
        // 销毁过滤器时调用的方法，可以在这里进行一些资源的释放操作
    }

}
